package com.star.gc4.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.star.gc4.common.R;
import com.star.gc4.entity.Log;
import com.star.gc4.entity.Menu;
import com.star.gc4.service.LogService;
import com.star.gc4.service.impl.LogServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogService logService;

    @GetMapping("/page")
    public R<Page> page(HttpServletRequest request, int page, int pageSize, @RequestParam(required = false) String name , @RequestParam(required = false)String singer){

        Page pageinfo =new Page(page,pageSize);
        LambdaQueryWrapper<Log> queryWrapper = new LambdaQueryWrapper<>();


        if (name !="" && name != null){
            queryWrapper.like(Log::getSongname,name);
        }
        if (singer !="" && singer !=null){
            queryWrapper.like(Log::getSinger,singer);
        }

        queryWrapper.orderByDesc(Log::getLogdate);
        logService.page(pageinfo,queryWrapper);
        return R.success(pageinfo);
    }
}
